let express = require("express")()
const { response } = require("express");
let expressStatic = require("express-static");
const { request } = require("http");
let mysql = require("mysql")
const port = 1000;

let sql = mysql.createConnection({
    host     : 'localhost',
    user     : 'root',
    password : '123456',
    database : 'test'
});

sql.connect();

express.get("/has",(request,response)=>{
    sql.query(`SELECT id,img,introduce,kind FROM list`,(error,data)=>{
        if(error){
            console.log(error)
        }
        else{
            response.send(data)
        }
    })
})


// express.get("/had",(request,response)=>{
//     sql.query(`SELECT content FROM list`,(error,data)=>{
//         if(error){
//             console.log(error)
//         }
//         else{
//             response.send(data)
//         }
//     })
// })


express.get("/getnews",(request,response)=>{
	let id = request.query.id;
	sql.query(`SELECT * FROM list WHERE id=${id}`,(error,data)=>{
		if(error){
			console.log(error);
			response.send("error");
		}
		else{
			response.send(data[0])
		}
	})
})


express.use(expressStatic(__dirname + '/mian'))
console.log(`runing of ${port}`)
express.listen(port)